using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Globalization;
using System.Threading.Tasks;
using UnityEngine;

public class TargetBall : BallBase
{
    public GameObject GoldObject;

    public int InitGold; //初始金钱

    private TrackedComponent trackedComponent = new TrackedComponent();
    // Start is called before the first frame update
    void Awake()
    {
        base.Awake();
        trackedComponent.Init(GoldObject.transform, gameObject.transform);
        trackedComponent.StartTrack();
    }

    void Start()
    {
        EventManager.Instance.Subscribe(ScreenChangeEvent.EventId, ScreenChangeCallBack);
        ScreenChangeCallBack(null, null);
    }

    // Update is called once per frame
    void Update()
    {
        trackedComponent.Update();
    }

    public override void FixedUpdate()
    {
        base.FixedUpdate();
        if (_rigidbody.velocity.y != 0)
        {
            _rigidbody.velocity = new Vector3(_rigidbody.velocity.x, 0, _rigidbody.velocity.z); //将y轴速度置为0
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        // if(collision.gameObject.layer == 10){
        //     GetComponent<TrailRenderer>().emitting = false;
        //     StartCoroutine(testaaa()); 
        // }
    }

    private void ScreenChangeCallBack(object sender, EventArgs ea)
    {
        if (Screen.width > Screen.height)
        {
        }
        else
        {
        }
    }

    // IEnumerator testaaa()
    // {
    //     GetComponent<TrailRenderer>().emitting = false;
    //     yield return new WaitForFixedUpdate();
    //     GetComponent<TrailRenderer>().emitting = true;

    // }

    public void OpenXifu()
    {
        // _rigidbody.velocity -= Time.fixedDeltaTime;
        _rigidbody.velocity -= _rigidbody.velocity * Time.fixedDeltaTime * 5; ;
    }

    public void CloseXifU()
    {

    }
}
